#-*- coding:utf-8 -*-

"""
装饰器指可以在代码运行期间动态为函数增加功能的方式，称之为装饰器
即decorator
"""

def log(func):
    def wrapper(*args, **kw):
        print "call %s():" % func.__name__
        return func(*argc, **kw)

    return wrapper


@log
def now():
    print "2017-11-12"


def log(text):
    def decorator(func):
        def wrapper(*args, **kw):
            print "%s %s():" % (text, func.__name__)
            return func(*args, **kw)
        return wrapper
    return decorator

@log('execute')
def now():
    print '2014-12-23'


import functools

def log(func):
    @functools.wraps(func)
    def wrapper(*args, **kw):
        print "call %s():" % func.__name__
        return func(*args, **kw)
    return wrapper


import functools
def log(text):
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kw):
            print "%s %s():" % (text, func.__name__)
            return func(*args, **kw)
        return wrapper
    return decorator